/*
 * Created on Jan 21, 2004
 */
package org.vectrics.company.client;


import java.util.List;
import org.vectrics.client.webclient.ServerCommandImpl;
import java.util.Vector;
import org.apache.log4j.*;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;



public class FindCompanyIds extends ServerCommandImpl {
	private transient static Logger log = Logger.getLogger(FindCompanyIds.class);
	private String firstName;
	private String lastName;
	private List companyIdList = new Vector();


	public FindCompanyIds() {
		super();
	}

	public String getCommandCode() {
		return("findCompanyIds");
	}

	protected void prepareRequestData(Element requestElement) {
		log.debug("prepareRequestData()");
	}

	public List getCompanyIdList() {
		return(companyIdList);
	}

	protected void processResponse(Element dataElement) {
		log.debug("processResponse() - translating XML document into user list");
		companyIdList.clear();
		NodeList nodeList = dataElement.getChildNodes();
		for (int i = 0; i < nodeList.getLength(); i++) {
			Node node = (Node)nodeList.item(i);
			if (node.getNodeType() == Node.ELEMENT_NODE) {
				Element dataChildElement = (Element)node; 
				if (dataChildElement.getNodeName().equals("companyList")) {
					NodeList companyList = dataChildElement.getElementsByTagName("company");
					
					for (int j = 0; j < companyList.getLength(); j++) {
						Element companyElement = (Element)companyList.item(j);
						
						log.debug("processResponse() - found another user XML Element");
						String id = companyElement.getAttribute("id");
						companyIdList.add(id);
					}
				}
				else {
					if (log.isDebugEnabled())
						log.debug("Error with data element child, expected 'userList', got: " + dataChildElement.getNodeName());
				}
			}
		}
	}


	/**
	 * @return
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * @param firstName
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * @return
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * @param lastName
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

}
